<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计评论数长度</title>
    <style>
        .box {
            width: 530px;
            display: flex;
            justify-content: space-between;
        }

        img {
            width: 50px;
            height: 50px;
            border-radius: 25px;
        }

        .box textarea {
            width: 400px;
            height: 50px;
            transition: all 0.7s;
        }

        #tx:focus {
            height: 100px;
            /* transition: all 0.5s; */
        }

        span {
            margin-left: 400px;
            opacity: 0;
            /* display: none; */
            transition: all 0.7s;
        }
    </style>
</head>

<body>

    <div class="box">
        <img src="img/娜美.jpg" alt="">
        <textarea maxlength="200" name="" id="tx" placeholder="发一条友善的评论"></textarea>
        <button>发布</button>
    </div>
    <span>0/200字</span>

    <script>

        //  ① ：判断用输入事件 input
        const tx = document.querySelector('#tx')
        const span = document.querySelector('span')
        tx.addEventListener('input', function () {
            // ② ：不断取得文本框里面的字符长度, 文本域.value.length
            // console.log(tx.value.length)
            // ③ ：把获得数字给下面文本框 
            span.innerHTML = `${tx.value.length}/200字`
        })

        tx.addEventListener('focus', function () {
            span.style.opacity = 1
        })

        tx.addEventListener('blur', function () {
            span.style.opacity = 0
        })

    </script>
</body>

</html>